package com.hq.fxh.No5_User.User.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hq.fxh.Modle.FollowUserModle;
import com.hq.fxh.Modle.PlateSoreModle;
import com.hq.fxh.R;
import com.hq.fxh.Utils.AppConstant;
import com.hq.fxh.Utils.GlideUtils;
import com.hq.fxh.Utils.Tool;

import java.util.List;

import static android.R.attr.data;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/9/15
 * @Email xlwenhao1858@sina.com
 */


public class Ladapter_GZ_Plate extends BaseAdapter {
    List<PlateSoreModle.DataBean> data;

    public void setData(List<PlateSoreModle.DataBean> data) {
        this.data = data;
    }

    @Override
    public int getCount() {
        return data == null || data.size() == 0 ? 0 : data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder viewHolder = null;
        if (view == null || !(view.getTag() instanceof ViewHolder)) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_gz_plate_name, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        if (data == null || data.size() < i + 1) {
            return null;
        }
        PlateSoreModle.DataBean dataBean = data.get(i);
        Tool.setStringToText(viewHolder.tvGZPlateName, dataBean.getCategory());
        Tool.setStringToText(viewHolder.tvGZPlateNum, dataBean.getItem_count() + "");

        GlideUtils.loadImageView(parent.getContext(), dataBean.getIcon(), viewHolder.imageGZPlateIcon);
        return view;
    }

    static class ViewHolder {
        protected ImageView imageGZPlateIcon;
        protected TextView tvGZPlateName;
        protected TextView tvGZPlateNum;
        protected LinearLayout layoutGZItem;
        protected TextView tvGZPlateFocus;

        ViewHolder(View rootView) {
            initView(rootView);
        }

        private void initView(View rootView) {
            imageGZPlateIcon = (ImageView) rootView.findViewById(R.id.image_GZ_Plate_icon);
            tvGZPlateName = (TextView) rootView.findViewById(R.id.tv_GZ_Plate_name);
            tvGZPlateNum = (TextView) rootView.findViewById(R.id.tv_GZ_Plate_num);
            layoutGZItem = (LinearLayout) rootView.findViewById(R.id.layout_GZ_Item);
            tvGZPlateFocus = (TextView) rootView.findViewById(R.id.tv_GZ_Plate_Focus);
        }
    }
}
